var windowName = "servicesPay";
var Page;
apiready = function(){
    onWindowShow(function () {
        console.log(windowName + " show")

    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        id:0,
        order:{},
        money:0,
        payType:100,
    },{
        //页面方法
        "init":function () {
            var data = getData4Page();
            logJson(data)
            this.id = data.order.id
            this.order = data.order
            this.money = data.order.payReal

            var intv ;
            //检测订单支付情况，如果支付完成提示跳转
            intv = setInterval(function () {
                apiGet("/app/order/check/pay", {id: Page.id}, function (res,code) {
                    if (code == 200) {
                        if (res.data == 1) {
                            clearInterval(intv)
                            showConfirm("订单支付完成，请前往“我的”，“我的订单”查看")
                        }
                    }else {
                        clearInterval(intv)
                    }
                });

            },1000);

        }
        ,doPay:function () {
            apiGet("/app/pay/order",{id:this.id ,type:this.payType},function (res,code) {
                log(res)
                log(code,"code")
                if (Page.payType == 100){
                    //微信支付
                    wxPay(res.data,function (ret) {
                        logJson(ret,"PAY_RET")
                    })
                }
                if (Page.payType == 200) {
                    //支付宝支付
                    aliPay(res.data,function (ret,err) {
                        logJson(ret,"ali_ret")
                        logJson(err,"ali_err")
                    });
                }
                // aliPay(res.data,function (ret,err) {
                //     logJson(ret,"ali_ret")
                //     logJson(err,"ali_err")
                // })
            })
        }
    })
    Page.init()
}